unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RzButton, ExtCtrls, RzPanel, StdCtrls, RzEdit,Thrad_WaitDemo;

type
  TForm1 = class(TForm)
    Tool_1: TRzToolbar;
    Btnv_1: TRzToolButton;
    Memo_1: TRzMemo;
    Btnv_2: TRzToolButton;
    procedure Btnv_1Click(Sender: TObject);
    procedure Btnv_2Click(Sender: TObject);
  private
  public
    //for tkzthrad
    procedure OnKzThradGetMaxProgress(Sender: TObject;AMaxProgress:Integer);
    procedure OnKzThradGetOneProgress(Sender: TObject;AOneProgress:Integer);
    procedure OnKzThradGetTxtProgress(Sender: TObject;ATxtProgress:string);
    procedure OnKzThradGetMsgProgress(Sender: TObject;AMsgProgress:string;AVarProgress:array of Variant);
    procedure OnTerminate(Sender:TObject);  
  end;

  procedure ThradMulti;stdcall;
  procedure ThradSingl;stdcall;




var
  Form1: TForm1;
  ThradwaitDemo:TThradWaitDemo;
  cHandle:THandle;

implementation

{$R *.dfm}

procedure TForm1.Btnv_1Click(Sender: TObject);
var
  ID:Cardinal;
begin
  CreateThread( nil, 0, @ThradMulti, nil, 0, ID );
end;

procedure ThradMulti;stdcall;
var
  I:Integer;
  Handles:TWOHandleArray;
  ThradwaitDemo:TThradWaitDemo;
begin
  for I := 0 to 10 do
  begin
    ThradwaitDemo := TThradWaitDemo.Create(False);
    ThradwaitDemo.OnKzThradGetMsgProgress := Form1.OnKzThradGetMsgProgress;
    Handles[I] := ThradwaitDemo.Handle;
  end;
  WaitForMultipleObjects( 11, @Handles, True, INFINITE );
  Form1.Memo_1.Lines.Add('all done');
end;

procedure ThradSingl;stdcall;
begin
  {#PASS:
  ThradwaitDemo := TThradWaitDemo.Create(False);
  ThradwaitDemo.OnKzThradGetMsgProgress := Form1.OnKzThradGetMsgProgress;
  cHandle:=ThradwaitDemo.Handle;
  WaitForSingleObject(cHandle,INFINITE);
  Form1.Memo_1.Lines.Add('one done');}

  ThradWaitDemo:=TThradWaitDemo.Create(True);
  ThradwaitDemo.OnKzThradGetMsgProgress := Form1.OnKzThradGetMsgProgress;  
  //#ThradwaitDemo.FreeOnTerminate:=False;
  ThradwaitDemo.Resume;  
  WaitForSingleObject(ThradWaitDemo.Handle,INFINITE);
  Form1.Memo_1.Lines.Add('one done');
end;

procedure TForm1.OnKzThradGetMaxProgress(Sender: TObject;
  AMaxProgress: Integer);
begin

end;

procedure TForm1.OnKzThradGetMsgProgress(Sender: TObject;
  AMsgProgress: string; AVarProgress: array of Variant);
begin
  self.Memo_1.Lines.Add(AVarProgress[0]);
end;

procedure TForm1.OnKzThradGetOneProgress(Sender: TObject;
  AOneProgress: Integer);
begin

end;

procedure TForm1.OnKzThradGetTxtProgress(Sender: TObject;
  ATxtProgress: string);
begin

end;

procedure TForm1.OnTerminate(Sender: TObject);
begin

end;

procedure TForm1.Btnv_2Click(Sender: TObject);
var
  ID:Cardinal;
begin
  CreateThread( nil, 0, @ThradSingl, nil, 0, ID );
end;

end.
